home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9429 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: web.cae.ca!usenet
  2. From: fraserh@cae.ca (Fraser Hutchinson)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Binary association problem
  5. Date: 1 Mar 1996 17:56:05 GMT
  6. Organization: CAE Electronics Ltd.
  7. Message-ID: <4h7dnl$qaf@web.cae.ca>
  8. References: <31296F14.88E@esec.ch> <Dn4Dt3.Kr5@ce.philips.nl>
  9. NNTP-Posting-Host: pch63.cae.ca
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=US-ASCII
  12. X-Newsreader: WinVN 0.99.7
  13.  
  14. In article <Dn4Dt3.Kr5@ce.philips.nl>, hartj@ce.philips.nl says...
  15. >
  16. >Oliver Plohmann <opl@esec.ch> writes:
  17. >
  18. >>Hello,
  19.  
  20. Hello
  21.  
  22. >
  23. >>I habe two classes that reference each other. I put those classes into
  24. >>one header to get the code linked. Due to the nature of my application I
  25. >>have now several class associated with each eather in one header. My
  26. >>compiler can't handle it any more and creates a fatal error. I could
  27. >>switch compiler but every compiler has some problem. I think it would
  28. >>only mean substituting problems for other problems.
  29.  
  30. This should not be a problem at all.
  31. [deleted]
  32.  
  33. >>Thank you, Olli Plohmann
  34. >
  35. >>-------------------------a.h------------------------
  36. >
  37. >>class B;
  38. >
  39. >>class A {
  40. >
  41. >>        int* x;
  42. >>public:
  43. >
  44. >>        A() {};
  45. >>        ~A() {};
  46. >
  47. >>        void operator+(const int& i) {
  48. >
  49. >>                *x=i;   // protection violation !
  50. >
  51. >OOPS?! Where is 'x' supposed to point to?
  52.  
  53. Well, this is secondary - should still compile and just corrupt memory at 
  54. runtime.
  55.  
  56. The real problem I suspect, is that the compiler sees you setting a reference 
  57. to a const and says "oops! you cannot do that!" - consts are supposed to be 
  58. read only and, (correct me if I am wrong, I am not near a reference source), 
  59. will not compile if you try to 'sneak around' the const this way.  If the 
  60. compiler let you do this, it might well let you modify the value of *x, thus 
  61. indirectly modifying a const.
  62.  
  63. Of course, I may be wrong :)
  64.  
  65.  
  66. Fraser
  67.  
  68.  
  69.  
  70.  
  71.